<?php
namespace Home\Model;
use \Frame\Libs\BaseModel;

final class LoginModel extends BaseModel{
	//注册，插入新用户的方法
	public function register($acc,$pwd,$name,$email,$phone,$sex,$qq){
		$sql = "INSERT INTO love_user (account,password,name,email,phone,sex,qq,reg_time) VALUES ('$acc','$pwd','$name','$email','$phone','$sex','$qq',now())";
		return $this->pdo->exec($sql);
	}
	
	//登录，判断是否存在这条记录
	public function login($acc,$md5pwd){
		$sql = "SELECT uid FROM love_user WHERE account='$acc' AND password='$md5pwd'";
		return $this->pdo->fetchOne($sql);
	}
	
	//获取某条记录的内容，用以存放SESSION
	public function query($acc){
		$sql = "SELECT * FROM love_user WHERE account='$acc'";
		return $this->pdo->fetchOne($sql);
	}
	
	//判断用户名、账户是否已存在
	public function isAccountExist($acc){
		$sql = "SELECT uid FROM love_user WHERE account='$acc'";
		return $this->pdo->rowCount($sql);
	}
	
	//判断手机号是否已存在
	public function isPhoneExist($phone){
		$sql = "SELECT uid FROM love_user WHERE phone='$phone'";
		return $this->pdo->rowCount($sql);
	}
	
	//判断邮箱是否已存在
	public function isEmailExist($email){
		$sql = "SELECT uid FROM love_user WHERE email='$email'";
		return $this->pdo->rowCount($sql);
	}
	
	//判断用户名邮箱匹配
	public function isAccEmailMatch($acc,$email){
		$sql = "SELECT uid FROM love_user WHERE account='$acc' AND email='$email'";
		return $this->pdo->rowCount($sql);
	}
	
	//修改密码
	public function updatePwd($account,$pwd){
		$sql = "UPDATE love_user SET password='$pwd' WHERE account='$account'";
		return $this->pdo->exec($sql);
	}
}
?>